#include  "msp430g2231.h" // Include the necessary header for our target MCU
 
void delay_ms(unsigned int ms ){ 		// Not really a milliseconds delay!
      unsigned int i;
      for (i = 0;i<= ms; i++){ 		// The operator is <=, I've yet to fix this site bug.
        __delay_cycles(500);
      }
}
 
void main(void) {
 
	WDTCTL = WDTPW + WDTHOLD;		// Hold the WDT (WatchDog Timer)
	P1DIR |= BIT1|BIT2|BIT3|BIT4;       		// Setup the appropriate output bits	
 	P2DIR |= BIT5; 
 	
	while(1) {
 
		 if( (!(P2IN & BIT0))&&(!(P2IN & BIT1)) ){				// Otherwise...
			P1OUT |= BIT2;
			P1OUT |= BIT1;
			P1OUT |= BIT4;
			P1OUT |= BIT3;
			P2OUT &= ~BIT5;
		}
		else if( (!(P2IN & BIT0))&&(!(P2IN & BIT2)) ){				// Otherwise...
			P1OUT |= BIT2;
			P1OUT |= BIT1;
			P1OUT |= BIT4;
			P1OUT |= BIT3;
			P2OUT |= BIT5;
		}
		else if ( !(P2IN & BIT0) ){		// If not (port one input AND bit3 (sw1))
			P1OUT |= BIT1;
			P1OUT &= ~BIT2;
			P1OUT &= ~BIT3;
			P1OUT |= BIT4;
			P2OUT &= ~BIT5;
		}
		else if( !(P2IN & BIT1) ){				// Otherwise...
			P1OUT |= BIT2;
			P1OUT &= ~BIT1;
			P1OUT &= ~BIT4;
			P1OUT |= BIT3;
			P2OUT &= ~BIT5;
		}
		else if( !(P2IN & BIT2) ){				// Otherwise...
			P1OUT |= BIT2;
			P1OUT &= ~BIT1;
			P1OUT |= BIT4;
			P1OUT |= BIT3;
			P2OUT &= ~BIT5;
		}
		else if( !(P2IN & BIT3) ){				// Otherwise...
			P1OUT |= BIT2;
			P1OUT |= BIT1;
			P1OUT |= BIT4;
			P1OUT &= ~BIT3;
			P2OUT &= ~BIT5;
		}
 delay_ms(500);
	}
 
}
